package com.aispace.taichu.configuration;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;

import java.util.Collections;

public class GeneratorCode {


    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/taichu-agent?characterEncoding=utf8&useSSL=false";
        String username = "root";
        String password = "123456";
        String projectPath = System.getProperty("user.dir");
        //项目工程
        String project = "/taichu-console";
        String outputXmlDir = projectPath + project + "/src/main/resources/mapper/";
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder ->
                        builder.author("chengjie.guo")
                                .outputDir(projectPath + project + "/src/main/java")
                                .commentDate("yyyy-MM-dd"))
                .packageConfig(builder ->
                        builder.parent("com.aispace.taichu.modules")
                                .pathInfo(Collections.singletonMap(OutputFile.xml, outputXmlDir))
                                .entity("model.entity")
                                .mapper("mapper")
                                .service("service")
                                .serviceImpl("service.impl")
                                .xml("mapper.xml"))
                .strategyConfig(builder ->
                        builder.entityBuilder()

                                .enableLombok()
                                .addTableFills(
                                        new Column("create_time", FieldFill.INSERT),
                                        new Column("update_time", FieldFill.INSERT_UPDATE)
                                )
                                .entityBuilder().idType(IdType.ASSIGN_ID)//主键策略  雪花算法自动生成的id
                                .mapperBuilder().enableBaseResultMap()
                                .entityBuilder().enableLombok()// 使用 Lombok
                                .enableTableFieldAnnotation() // 启用字段注解
                                .controllerBuilder()
                                .enableRestStyle() // 启用 REST 风格
                )
                .strategyConfig(builder ->
                                builder.addInclude("llm_model_config") // 设置需要生成的表名
                        .addTablePrefix("llm_") // 设置过滤表前缀
                ).templateEngine(new FreemarkerTemplateEngine()).execute();
    }
}
